package com.ipzoe.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ipzoe.cms.domain.Case;
import com.ipzoe.cms.mapper.CaseMapper;
import com.ipzoe.cms.service.ICaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 案例Service业务层处理
 *
 * @author eric
 * @date 2020-08-15
 */
@Service
public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements ICaseService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeByIds(Collection<? extends Serializable> idList, String updateBy) {

        boolean result = update(Wrappers.<Case>lambdaUpdate().set(Case::getUpdateBy, updateBy)
                .set(Case::getUpdateTime,new Date())
                .in(Case::getId,idList));

        return result && removeByIds(idList);
    }

    @Override
    public List<Case> selectAllOnUse() {
        return this.baseMapper.selectList(new QueryWrapper<Case>().orderByAsc(Case.COLUNM_ORDER_NUM).eq(Case.COLUMN_USE_FLAG, 1));
    }
}
